package com.example.service.impl;

import com.example.mapper.StudentMapper;
import com.example.pojo.ParseStudent;
import com.example.pojo.Score;
import com.example.pojo.Student;
import com.example.service.StudentService;
import jdk.jfr.TransitionTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Vector;

@Service
public class StudentServiceimpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Transactional
    @Override
    public void add(String id, String name, String passwd, String aClass) {
        studentMapper.addStudent(id,name,aClass);
        studentMapper.addStudentPasswd(id,passwd);
    }

    @Override
    public Vector<ParseStudent> select() {
        Vector<ParseStudent> students = studentMapper.select();

        return students;
    }

    @Override
    public Vector<ParseStudent> selectStudent(String id, String aaClass,String teacher,String name) {
        Vector<ParseStudent> parseStudents=studentMapper.selectStudent(id,aaClass,teacher,name);
        return parseStudents;
    }

    @Override
    public void update(ParseStudent parseStudent) {

        studentMapper.update(parseStudent.getName(),parseStudent.getAaClass(),parseStudent.getCourse(),parseStudent.getScore(),parseStudent.getId());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(String id) {
        studentMapper.delete_1(id);
        studentMapper.delete_2(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void studentCourse(String sid,String cid,String course,String name) {
        studentMapper.studentCourse(cid,course,name);
        studentMapper.studentScore(sid,name,course,"暂未考试");
    }
}
